<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>学生信息页面</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <th:block th:replace="/common_resources::common_css"></th:block>
    <th:block th:replace="/common_resources::common_js"></th:block>

</head>

<body class="hold-transition skin-purple sidebar-mini">

<header th:replace="~{/common_header::header}"></header>
<aside th:replace="/common_aside::aside"></aside>

<div class="wrapper">

    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                学生信息管理
                <small>学生信息列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="/student/all">学生信息管理</a></li>
                <li class="active">学生信息列表</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!-- .box-body -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">列表</h3>
                </div>

                <div class="box-body">

                    <!-- 数据表格 -->
                    <div class="table-box">

                        <!--工具栏-->
                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <a th:href="@{/class/all}">
                                        <button type="button"  class="btn btn-default" title="新建"><i class="fa fa-file-o"></i> 新建</button>
                                    </a>

                                </div>
                            </div>
                        </div>

                        <div class="box-tools pull-right" style="width: 300px">

                                <div class="has-feedback">
                                    <form th:action="@{/student/findByLike(condition=${condition})}" method="get">
                                        <div class="input-group margin">
                                            <input type="text" name="condition" th:value="${condition}" class="form-control">
                                            <span class="input-group-btn">
                                                <button type="submit" class="btn btn-info btn-flat" >搜索</button>
                                            </span>
                                        </div>
                                    </form>
                                </div>

                        </div>

                        <!--工具栏/-->

                        <!--数据列表-->
                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>

                                <th >学号</th>
                                <th >姓名</th>
                                <th >性别</th>
                                <th >生日</th>
                                <th >电话</th>
                                <th >班级</th>
                                <th >班主任</th>
                                <th >操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <tr th:each="students:${studentVOIPage.records}">
                                <input type="hidden" th:value="${students.id}" id="teacherId">
                                <td th:text="${students.username}"></td>
                                <td th:text="${students.name}"></td>
                                <td th:text="${students.sex}"></td>
                                <td th:text="${#dates.format(students.birthday,'yyyy-MM-dd')}"></td>
                                <td th:text="${students.phoneNumber}"></td>
                                <td th:text="${students.className}"></td>
                                <td th:text="${students.teacherName}"></td>
                                <td class="text-center">
                                    <a th:href="@{/student/updateById(id=${students.id})}">
                                        <button type="button" class="btn bg-olive btn-xs" >修改</button>
                                    </a>

                                    <button type="button" class="btn bg-red btn-xs" th:id="${students.id}" onclick="delStudent(this.id)">删除</button>

                                </td>
                            </tr>

                            </tbody>

                        </table>
                        <!--数据列表/-->


                    </div>
                    <!-- 数据表格 /-->


                </div>
                <!-- /.box-body -->

                <!-- .box-footer-->
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共 <span th:text="${studentVOIPage.pages}"></span> 页，
                            共<span th:text="${studentVOIPage.total}"></span> 条数据
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination"></ul>
                    </div>

                </div>
                <!-- /.box-footer-->



            </div>

        </section>
        <!-- 正文区域 /-->

    </div>

</div>
<script>

    function delStudent(id) {
        if (confirm("是否删除？")==true){
            deleteStudent(id);
        }
    };
    function update(studentId) {
        console.log(studentId);
        $.get("/student/updateById",{studentId:studentId},function (result){

        })
    }
    function deleteStudent(studentId) {


        console.log(studentId);
        $.get("/student/delete",{studentId:studentId},function (result){

            alert(result);
            location.href="/student/all";
        })
    };

</script>
<footer th:replace="~{/common_footer::footer}"></footer>
<script th:inline="javascript">

    var currentPage=[[${studentVOIPage.current}]];
    var pages=[[${studentVOIPage.pages}]];
    var context=[[${#servletContext.contextPath}]];
    var condition=[[${condition}]];
    // 分页插件

    $(".pagination").bootstrapPaginator({
        bootstrapMajorVersion: 3, // bootstrap版本
        currentPage: currentPage, // 当前页
        totalPages: pages, // 总页数
        numberOfPages: 5, // 最多显示多少页
        itemTexts: function (type, page, current) {
            switch (type) {
                case "first":
                    return "首页";
                case "prev":
                    return "上一页";
                case "next":
                    return "下一页";
                case "last":
                    return "末页";
                case "page":
                    return page;
            }
        },
        onPageClicked: function (event, originalEvent, type, page) { // 点击页码执行的方法
            if (condition==null){
                location.href =context+ "/student/all?page=" + page;
            }else {
                location.href =context+ "/student/findByLike?page=" + page+"&condition="+condition;
            }


        }
    });

</script>
</body>

</html>